﻿using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.CSharp;

namespace QuickRunnable
{
    class QuickCodeDomExample
    {
        public String CreateExpression() {
            String[] expressions = {"Pos.Symbol", "Pos.Trader"};

            var expression = new CodePropertyReferenceExpression(
                new CodeThisReferenceExpression(), "A"
                );

            // it's pretty handy that you have a user dictionary to just slap shit onto it.
            return EvaluateCodeDom( expression );
        }

        // in order to use this to its fullest, what we would really need to do is 
        // assure, completely, that I have something of a full expression tree. (?)

        private String EvaluateCodeDom( CodeExpression expression ) {
            CSharpCodeProvider provider = new CSharpCodeProvider();
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            provider.GenerateCodeFromExpression(expression, sw, new CodeGeneratorOptions());
            return sb.ToString();
        }
    }
}
